#ifndef RDCONN_H
#define RDCONN_H

#include "connect.h"

#define APP1		(uint8)'R'
#define APP2		(uint8)'D'

#define GAMEID	8				// Red Dog
#define MACHID	(uint8)0		// Red Dog only has one "machine"

class RedDogGame;
class RedDogHand;

class RedDogConnection : public Connection
{
	public:
		RedDogConnection(Server*server, SOCKET client);
		~RedDogConnection();

		void msgStart();
		void msgAdd(uint8 Byte);
		void msgAdd(int32 SignedLong);
		uint8* msgGetBuf();
		void msgReleaseBuf(int32 Amt);
		void msgEnd();

		bool8	trackGetBalance(int32 *);
		int32	trackAdjustBalance(int32);	// + increases  - decreases
		bool8	trackGetPlayerLimits(int32* minBet, int32* maxBet,
					int32* compFactor);
		bool8	trackNewGame(int32 Bet, int32* Balance);
		bool8	trackDeal(RedDogHand* Player, uint8 endingType, int32 outcome,
					int32 BalAdjust, int32* Balance);
		bool8	trackGameDone(uint8 ThirdCard, bool8 Raised, int32 outcome,
					int32 BalAdjust, int32* Balance);

		bool8	trackHasSavedGame(int32* err);
		bool8	trackSaveGame();
		bool8	trackRemoveSavedGame();
		void	trackaddBadPacket(int32 error_reason, char MessageType, char *msgbuf, int32 msglen);
		int32	trackValidateLogin();
		int32	trackValidateSession();

		// CSN-7075: New Authentication
		void	trackLogoutSession();

		#ifdef FORCEDSHOE 
        String  GetPID() {return m_pid;}
        #endif

	protected:
		bool8	getResponse();

		void	handleLogin(int32 len);

		void	sendStopMsg();

		bool8	parseCasinoLogin(int32, int32*);
		bool8	parseUnicodeCasinoLogin(int32, int32*);

		void	removeCasinoSpecific();

		int32	encode(uint8*, uint8*, int32);
		int32	decode(uint8*, uint8*, int32);

		int32	msgRemove(uint8*, int32*);

	public:
		void	gameDone();

	protected:
		int32 loggedOn;
		RedDogGame* game;
		void* casinoSpecific;
		int32 minBet, maxBet;
		int32 compFactor;
		int32 msglen;
		uint8 msgbuf[256];
		#ifdef FORCEDSHOE     
			String m_pid;
		#endif

	// [AO 2008-01-16] Refactoring for HA
	private:
		bool ValidateSession();
};

#endif
